This document attempts to explain how to interpret data received using the UconX Synchronous Bit Stream Receiver and Synchronous Bit Stream Interface.
1. Background
Most synchronous serial communication protocols use an "opening flag" (bit synchronous) or one or more "sync characters" (byte synchronous) at the start of each block of data transmitted so the receiver can synchronize, or align, received data on the same byte boundary as the data that was transmitted.
UconX's Synchronous Bit Stream (SBS) products are designed for cases where no such protocol exists. They can be used to transmit and receive a continuous bit stream when the only means of synchronization is the clock signal itself. In this case, the serial device must be "externally" or artificially synchronized. As a result, the SBS software cannot align received data on any particular byte boundary.
It is the responsibility of the client application program to analyze and interpret the received data, reconstructing it, if necessary, to match the byte alignment of the original data before transmission across the serial link.
2. Bit Ordering on the Serial Line
UconX supports the SBS products on several different hardware platforms. In all cases, the serial devices operate in a similar fashion in terms of the ordering of bits on the serial line. For each 8-bit byte to be transmitted, the least-significant bit (LSB) is transmitted first. Likewise, the first bit received on the serial line is stored in the low-order bit of a byte. We refer to this as LSB mode. Some other hardware devices transmit and receive data most-significant-bit (MSB) first.
On first evaluation, it would seem to make no difference in which order the bits within each byte are transmitted and received, as long as both transmitter and receiver operate in the same mode. As long as the byte boundaries remain intact, this is true. However, when byte boundaries in the received data must be reconstructed, bit ordering on the serial line is a significant consideration, as we shall see.
3. Reversing Bits in Software
The SBS products provide configuration options for bit ordering on transmit and receive. If LSB mode is selected, data is transmitted and received without modification. If MSB mode is selected, the bits within each byte are reversed (as in a mirror image) before transmission or after reception. When MSB mode is selected, the SBS software simulates a serial device operating in MSB mode.
4. Transmission and Reception of Byte-Aligned Data
In this section, we look at the transmission and reception of byte-aligned data, using, as an example, a sequence of four 8-bit bytes.
Values to be transmitted:
The least-significant bit of each byte is transmitted first. The order of the bits on the line is as follows:
For each byte, the first bit received on the line is stored in the low-order bit. The received data is stored as follows:
The received data, as you can see, is identical to the transmitted data. This will always be true when you are using a synchronized protocol. When you are using SBS, it can happen by chance that received data is aligned on the same boundary as the transmitted data.
5. Non-Byte-Aligned Data in LSB Mode
Now, suppose that the serial device is not synchronized on a byte boundary. When the first bit of our example data arrives, a byte has already been partially filled with some preceding data. (As described in section 1, this can easily happen when using SBS.) In this case, the received data is stored as follows, where the Xs represent unknown bits preceding and following our example data:
Looking carefully at the resulting data, you can see that simply shifting the entire bit stream right or left will not restore the original pattern. The data must be shifted through the bytes in the same sequence that was used by the receiver as the data was pulled off the serial line; that is, from LSB to MSB within each byte.
In other words, to shift the entire bit stream left, you must shift each byte left. The MSB is shifted into the LSB of the following byte. The new LSB comes from the MSB of the preceding byte. Figure 5.1 illustrates this procedure.
To shift the bit stream right, reverse the operation. As each byte is shifted right, the LSB is shifted to the MSB of the preceding byte, and the MSB is brought from the LSB of the following byte. This procedure is shown in Figure 5.2.
6. Non-Byte Aligned Data in MSB Mode
For data transmitted and received MSB first, analysis of the resulting bit stream is much easier.
Start with the same values to be transmitted:
The most-significant bit of each byte is transmitted first. The order of the bits on the line is as follows:
If the serial device is not synchronized on a byte boundary, and a byte has already been partially filled by preceding data, the received data might look like this:
To realign the data on its original byte boundaries, we can simply shift the entire bit stream right or left until the original pattern is restored. Just as before, the data must be shifted through the bytes in the same sequence that was used by the receiver; in this case, from MSB to LSB within each byte.
To shift the entire bit stream left, you must shift each byte left. The MSB is shifted into the LSB of the preceding byte. The new LSB comes from the MSB of the following byte. To shift the bit stream right, do the opposite. As each byte is shifted right, the LSB is shifted to the MSB of the following byte, and the MSB is brought from the LSB of the preceding byte.
The pattern is much easier to "see" because we visualize the LSB of one byte as being adjacent to the MSB of the next byte, and so on. Although the UconX hardware platforms don't support MSB transmission and reception, you can configure SBS to simulate this mode of operation, as described in the next section.
7. Simulating MSB Mode by Reversing Bit Ordering
If you are receiving data from a device that transmits in MSB mode, you can configure the UconX SBS software to simulate MSB mode on reception. If your data is transmitted and received using SBS, you can simulate MSB mode on both sides. You might want to do this if you find it easier to analyze received data with the bits in an MSB sequence. However, you should be aware that this simulation adds a significant overhead to the SBS software and limits your maximum line speed.
The following example shows transmission and reception with MSB simulation on both sides. We'll start with the same values to be transmitted:
SBS reverses the bits within each byte before transmitting:
The data is transmitted least-significant bit first, as always:
They are received least-significant bit first on a non-byte-aligned boundary:
SBS reverses the bits after reception:
Because we've simulated transmission and reception in MSB mode, the resulting bit pattern is in sequence from left to right, and we can shift the bits as described in section 6.
The same result is obtained if you are using SBS to receive data from a device that is actually transmitting in MSB mode. Our transmitted values are as before:
The transmitting device sends MSB first. The order of the bits on the line is as follows:
The UconX receiving device stores the data LSB first:
You have configured SBS to reverse the bits after reception:
8. Analyzing Data Received in LSB Mode
If you must receive in LSB mode, but would prefer to analyze the data by shifting it in an "MSB-style" pattern, there is an option. The following example uses the data received in section 5 and shows how your can search for the pattern of the first byte transmitted (0x72).
The data was received as follows:
First, reverse the bits within each byte (it's most efficient to do this with a table-lookup, where the table has 256 entries, each containing the reversed pattern of the index to that entry):
Now, search at each bit offset until you find a pattern matching the mirror image of 0x72 (0100 1110). You'll find the pattern beginning at an offset of three bits into the data stream. To align the data on its original byte boundaries, shift it left three bits as you would for data received in MSB mode. (The MSB of each byte shifts to the LSB of the preceding byte.) Discarding the "unknown" data (represented by Xs), the result is as follows:
Finally, reverse the bits within each "new" byte, and the original data is restored:
Ordering Information: For more information or to place an order, please contact us at (619) 627-1700 or email us at sales@uconx.com . For technical questions about our products, please email us at tech@uconx.com .